import React, { ReactElement } from 'react'
import { ConnectProps, ConnectState, UserModelState } from '../models/types'
import { connect, Redirect } from 'umi'
interface SecurityLayoutProps extends ConnectProps {
    user: UserModelState,
    children: ReactElement
}
const SecurityLayout: React.FC<SecurityLayoutProps> = ({ user, children, location }) => {
    const { currentUser: { userid } } = user
    const isLogin = !!userid
    if (!isLogin) {
        return <Redirect to={{ pathname: '/login', state: { from: location.pathname } }}></Redirect>
    }
    return <div>{children}</div>


}

export default connect(({ user }: ConnectState) => ({ user }))(SecurityLayout)